package com.hongye.hongyemq.listener;

import com.aliyuncs.exceptions.ClientException;
import com.hongye.hongyemq.util.SendSmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;


@Slf4j
@RabbitListener(queues = "phone.queue")
@Component
public class MyListener {
    @Autowired
    SendSmsUtil sendSmsUtil;

    @RabbitHandler
    public void  getMyQueue(HashMap<String,String> map) throws ClientException {
        log.info("你接收到的验证码是:"+map.get("code"));
        //发送短信
        String phone = map.get("phone");
        String code = map.get("code");
        try {
            sendSmsUtil.sendMsg(phone,code);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
